package queue.practise;

class MyCircularQueue {
    private int[] queue;
    private int len;
    public MyCircularQueue(int k) {
        queue = new int[k];
        len = k;
    }
    private int front;
    private int rear;
    private int useSize;
    public boolean enQueue(int value) {
        if(isFull()) {
            return false;
        }
        queue[rear] = value;
        rear = (rear + 1) % len;
        useSize++;
        return true;
    }
    
    public boolean deQueue() {
        if(isEmpty()) {
            return false;
        }
        front = (front + 1) % len;
        useSize--;
        return true;
    }
    
    public int Front() {
        return isEmpty() ? -1 : queue[front];
    }
    
    public int Rear() {
        return isEmpty() ? -1 : queue[((rear - 1) % len + len) % len];
    }
    
    public boolean isEmpty() {
        return useSize == 0;
    }
    
    public boolean isFull() {
        return useSize == len;
    }
}